from django.db import models
from datetime import datetime

# Create your models here.


class HuaweiCategory(models.Model):
    objects = models.Manager()
    categoryName = models.CharField("类别名称", max_length=200)

    class Meta:
        verbose_name = "商品总类别"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.categoryName


class HuaweiSubCateGory(models.Model):
    objects = models.Manager()
    subCategoryName = models.CharField("类目名称", max_length=200)
    parentCategory = models.ForeignKey(
        HuaweiCategory,
        on_delete=models.CASCADE,
        related_name="parentCategory",
        verbose_name="商品父类",
    )

    class Meta:
        verbose_name = "商品子类别"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.subCategoryName


class HuaweiGoods(models.Model):
    objects = models.Manager()
    goodName = models.CharField("商品名称", max_length=200)
    goodCoverImg = models.CharField("商品封面图", max_length=500)
    goodPrice = models.IntegerField("价格")
    goodDetailNmae = models.CharField("商品详细页标题", max_length=350)
    goodCategory = models.ForeignKey(
        HuaweiSubCateGory,
        on_delete=models.CASCADE,
        related_name="subCategory",
        verbose_name="商品子分类",
    )
    mainCategory = models.ForeignKey(
        HuaweiCategory,
        on_delete=models.CASCADE,
        related_name="mainCategory",
        verbose_name="总分类",
    )
    goodNums = models.IntegerField("商品数量", default=100)
    goodClickNums = models.IntegerField("点击量", default=10)
    goodSoldNums = models.IntegerField("销售量", default=0)
    goodShipFree = models.BooleanField("是否免运费", default=True)
    goodFavNums = models.IntegerField("收藏量", default=0)
    good_is_new = models.BooleanField("是否新品", default=True)
    good_is_hot = models.BooleanField("是否热销", default=True)
    good_is_oncounting = models.BooleanField("是否打折", default=True)
    good_add_time = models.DateTimeField("添加时间", default=datetime.now)

    class Meta:
        verbose_name = "商品详细"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.goodName


class HuaweiGoodsDetialImgList(models.Model):
    objects = models.Manager()
    images = models.CharField("商品详细大图", max_length=300)
    imagessmall = models.CharField("商品详细缩略图", max_length=300)
    goods = models.ForeignKey(
        HuaweiGoods,
        on_delete=models.CASCADE,
        related_name="gooddetialimg",
        verbose_name="所属商品",
    )

    class Meta:
        verbose_name = "商品详细图片"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.goods


class HuaweiGoodContentImageList(models.Model):
    objects = models.Manager()
    images = models.CharField("商品内容图", max_length=300)
    goods = models.ForeignKey(
        HuaweiGoods,
        on_delete=models.CASCADE,
        related_name="goodcontentimg",
        verbose_name="所属商品",
    )

    class Meta:
        verbose_name = "商品详细内容图片"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.goods


class HuaweiGoodDetialInfos(models.Model):
    objects = models.Manager()
    detailName = models.CharField("商品参数名", max_length=150)
    detialValue = models.CharField("商品参数值", max_length=450)
    goods = models.ForeignKey(
        HuaweiGoods,
        on_delete=models.CASCADE,
        related_name="goodinfos",
        verbose_name="所属商品",
    )

    class Meta:
        verbose_name = "商品详细参数"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.detailName
